<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title></title>
		<!--标准mui.css-->
		<link rel="stylesheet" href="../css/mui.min.css">
		<!--App自定义的css-->
		<link href="css/mui.min.css" rel="stylesheet" />
		<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
		<link rel="stylesheet" type="text/css" href="css/ymk.css" />
		<link rel="stylesheet" type="text/css" href="css/style.css" />
		<script src="js/mui.min.js"></script>
		<script type="text/javascript" src="js/jquery-form.js"></script>
		<script type="text/javascript" src="js/my.js" ></script>

	</head>

	<body>
		<header class="mui-bar mui-bar-nav public-color">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">退宿申请</h1>
		</header>
		<div class="mui-content">
			<form class="mui-input-group  tjxdz" id="form1">
				<input type="text" placeholder="申请人姓名" name="name" id="name" readonly="true">
				<input type="text" placeholder="申请人手机号" name="username" id="username">
				<input type="hidden" name="user_id" id="user_id" />
				<input type="text" placeholder="入住时间" name="start_time" id="start_time" readonly="true" />
			</form>
			<button class="public-g-btn btn-block" id="sure">确认</button>

		</div>
		<script type="text/javascript">
			mui.init();
			var userInfo = JSON.parse(localStorage.getItem("userInfo"));
			var url = localStorage.getItem("url");
			var realUrl = url + "/user/getUser"
			mui.ajax(realUrl, {
				data: {
					id: userInfo,
				},

				//服务器返回json格式数据 
				type: 'post', //HTTP请求类型
				timeout: 10000, //超时时间设置为10秒；
				success: function(data) {
					if(data.code == 0) {
						$("#name").val(data.data.name);
						$("#username").val(data.data.username);
						var starttime = data.data.startTime;
						if(starttime == null || starttime == "") {
							mui.alert("你还没有入住");
							return;
						} else {
							$("#start_time").val(starttime);

						}

					}

				},
				error: function(xhr, type, errorThrown) { //异常处理；
					console.log(type);
				}
			});

			var sure = document.getElementById("sure");
			sure.addEventListener('tap', function() {
				var phone = /^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\d{8}$/;
				var input = document.getElementsByTagName("input");
				var username = input[1].value;
				if(username == '') {
					mui.alert("手机号不能为空");
					return;
				}
				if(username.length != 11) {
					mui.alert("手机号应为11位", {
						duration: 'short',
						type: 'div'
					});
					return;
				}
				if(!phone.test(username.trim())) {
					mui.alert("手机号格式不正确");
					return;
				}
				var realUrl = url + "/mobilereview/retireApply"
				var userInfo = JSON.parse(localStorage.getItem("userInfo"));
				mui.ajax(realUrl, {
					data: {
						user_id: userInfo,

					},
					//服务器返回json格式数据 
					type: 'post', //HTTP请求类型
					timeout: 10000, //超时时间设置为10秒；
					success: function(data) {
						if(data.code == 0) {
							mui.alert(data.msg);
							my.jump("index.html","retire_apply");
						} else {
							mui.alert(data.msg);
						}

					},
					error: function(xhr, type, errorThrown) { //异常处理；
						console.log(type);
					}
				});
			});
		</script>

	</body>

</html>